package com.example.yoho.mvp.view.activity;



import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RadioButton;

import com.example.lib_core.mvp.view.BaseActivity;
import com.example.yoho.R;
import com.example.yoho.di.component.DaggerHomeComponent;
import com.example.yoho.di.moudles.HomeModules;
import com.example.yoho.mvp.contract.HomeContract;
import com.example.yoho.mvp.model.entity.BannerEntity;
import com.example.yoho.mvp.model.entity.HomeGoodsEntity;
import com.example.yoho.mvp.model.entity.RecommendEntity;
import com.example.yoho.mvp.model.entity.UpgradeEntity;
import com.example.yoho.mvp.presenter.HomePresenter;
import com.example.yoho.mvp.view.fragment.CommunityFragment;
import com.example.yoho.mvp.view.fragment.HomeFragment;
import com.example.yoho.mvp.view.fragment.MineFragment;
import com.example.yoho.mvp.view.fragment.SortFragment;
import com.example.yoho.mvp.view.fragment.UFOFragment;
import com.example.yoho.utils.MyGlide;

import java.util.List;

public class MainActivity extends BaseActivity<HomePresenter> implements HomeContract.View, View.OnClickListener {

    private HomeFragment homeFragment;
    private CommunityFragment communityFragment;
    private MineFragment mineFragment;
    private UFOFragment ufoFragment;
    private SortFragment sortFragment;
    private static final String TAG = "MainActivity";
    private android.widget.RadioButton raHome;
    private android.widget.RadioButton raSort;
    private android.widget.ImageView ufo;
    private android.widget.RadioButton raCommuntiy;
    private android.widget.RadioButton raMine;
    private FrameLayout vwpage;


    @Override
    public int bondLayout() {
        return R.layout.activity_main;
    }

    @Override
    public void Inject() {
        DaggerHomeComponent.builder().homeModules(new HomeModules(this)).build().Inject(this);
    }

    @Override
    public void initView() {
        raHome = (RadioButton) findViewById(R.id.ra_home);
        raSort = (RadioButton) findViewById(R.id.ra_sort);
        ufo = (ImageView) findViewById(R.id.ufo);
        raCommuntiy = (RadioButton) findViewById(R.id.ra_communtiy);
        raMine = (RadioButton) findViewById(R.id.ra_mine);
        raHome.setOnClickListener(this);
        raSort.setOnClickListener(this);
        raCommuntiy.setOnClickListener(this);
        raMine.setOnClickListener(this);
        ufo.setOnClickListener(this);
        vwpage = (FrameLayout) findViewById(R.id.vwpage);
    }

    @Override
    public void initData() {
        homeFragment=new HomeFragment();
        sortFragment=new SortFragment();
        ufoFragment=new UFOFragment();
        communityFragment=new CommunityFragment();
        mineFragment=new MineFragment();
        MyGlide.GlideIntCirclye(this,R.drawable.home_tab_ufo,ufo);
        getSupportFragmentManager().beginTransaction().add(R.id.vwpage,homeFragment).add(R.id.vwpage,sortFragment).add(R.id.vwpage,communityFragment).add(R.id.vwpage,ufoFragment).add(R.id.vwpage,mineFragment).show(homeFragment).hide(sortFragment).hide(ufoFragment).hide(communityFragment).hide(mineFragment).commit();
    }

    @Override
    public void showBanner(List<BannerEntity.Values> bannerEntities) {
        Log.e(TAG, "showBanner: "+bannerEntities.size() );
    }

    @Override
    public void showRecommend(RecommendEntity recommendEntities) {

    }


    @Override
    public void showGoods(List<HomeGoodsEntity.Values> homeGoodsEntities) {
        Log.e(TAG, "showGoods: " +homeGoodsEntities.size());
    }

    @Override
    public void showLoadGoods(List<HomeGoodsEntity.Values> homeGoodEntities) {

    }

    @Override
    public void showUpgrade(UpgradeEntity entity) {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.ra_home:
                getSupportFragmentManager().beginTransaction().show(homeFragment).hide(sortFragment).hide(ufoFragment).hide(communityFragment).hide(mineFragment).commit();
                break;
            case R.id.ra_sort:
                getSupportFragmentManager().beginTransaction().hide(homeFragment).show(sortFragment).hide(ufoFragment).hide(communityFragment).hide(mineFragment).commit();
                break;
            case R.id.ufo:
                getSupportFragmentManager().beginTransaction().hide(homeFragment).hide(sortFragment).show(ufoFragment).hide(communityFragment).hide(mineFragment).commit();
                break;
            case R.id.ra_communtiy:
                getSupportFragmentManager().beginTransaction().hide(homeFragment).hide(sortFragment).hide(ufoFragment).show(communityFragment).hide(mineFragment).commit();
                break;
            case R.id.ra_mine:
                getSupportFragmentManager().beginTransaction().hide(homeFragment).hide(sortFragment).hide(ufoFragment).hide(communityFragment).show(mineFragment).commit();
                break;
        }
    }
}
